var dbCongif=require('../utif/dbconfing')
// 获取当前时间
function createdtime(){
  return new Date().toLocaleString()
}
//登录
login=(req,res)=>{
    let users=req.body.username;
    let password=req.body.password;
    console.log(req.body)
    var sql=`select * from t_users where username=? and password=?`;
    var sqlArr=[users,password];
    var callBack=(err,data)=>{
        if(err) return console.log('连接出错了')
        res.send({
          'list':data
        })
      }
      dbCongif.sqlConnect(sql,sqlArr,callBack)
}
// 查询用户
getuser=(req,res)=>{
  let username=req.body.username
  var sql=`select username from t_users where username=?`;
  var sqlArr=[username]
  var callBack=(err,data)=>{
    if(err) return console.log('连接出错了')
    res.send({
      'list':data.length?true:false
    })
  }
  dbCongif.sqlConnect(sql,sqlArr,callBack)
}
// 注册
register=(req,res)=>{
  let username=req.body.username;
  let password=req.body.password;
  let nikiname=req.body.nikiname;
  let email=req.body.email;
  var sql=`insert into t_users (username,password,nikiname,email) value("${username}","${password}","${nikiname}","${email}")`;
  var sqlArr=[]
  var callBack=(err,data)=>{
    if(err) return console.log('连接出错了')
    res.send({
      'list':data
    })
  }
  dbCongif.sqlConnect(sql,sqlArr,callBack)
}
module.exports={
    login,
    register,
    getuser
}